//选项卡切换
$(".account li").click(function(){
    $(".account li").removeClass("Selection");
    $(this).addClass("Selection");
    var n=$(this).index();
    $(".account-set > div").hide();
    $(".account-set > div").eq(n).show();
    if(n == 1){
        $(".account-phone-2").hide();
        $(".account-phone-1").show();
    }
})


//下一步
$(".account-phone-1 .btn-a").click(function(){
    var code = $('.m_code_1').val();
    if(code.length == 0){
        $(".m_code_1").nextAll(".warning").removeClass('hide').show();
    }else{
        $(".account-phone-1").hide();
        $(".account-phone-2").show(); 
    }
    
})



//当选择显示昵称时验证昵称
$('.nickname').blur(function(){
    var check = $('input[name="Head[is_show_truename]"]:checked').val();
    var nickname = $(".nickname").val();
    if(check == 0 && nickname.length == 0){
        $(".nickname").nextAll(".warning").removeClass('hide').show();
    }else{
        $(".nickname").nextAll(".warning").addClass('hide').hide();
    }
})

//设置结果提交
$(".btn-set").click(function(){
    var e = window.event || e,
       errNum = 0;
    if(e.preventDefault){
        e.preventDefault();
    }else{
        window.event.returnValue = false; 
    }

    $('input').trigger('blur');
    errNum = $('span.warning:visible').length;
    if (errNum == 0) {
        $('.submit_form').get(0).submit();
    }
})




//旧手机发验证码
$('.send_message1').click(function(event) {   
    var identity = $(this).attr('data-identity');
    var type = $(this).attr('data-code-type');
    var obj = $(this).get(0);
    $.post(
        api_url + '/v1/home/code/create', 
        {identity: identity, mobile: oldMobile, type: type, _csrf:$('.request-csrf').val()}, 
        function(res) {
            // bootbox.alert(res.msg);                
    }, 'json');
});

//发送手机验证码
$('.send_message').click(function(event) {
    var identity = $(this).attr('data-identity');
    var mobile = $('.mobile').val();
    var type = $(this).attr('data-code-type');
    var obj = $(this).get(0);
    $.post(
        api_url + '/v1/home/code/create', 
        {identity: identity, mobile: mobile, type: type, _csrf:$('.request-csrf').val()}, 
        function(res) {
            // bootbox.alert(res.msg);                
    }, 'json');
    
});



//ajax验证手机验证码
$('.m_code_1').blur(function(){
    var code = $(this).val();
    var identity = $('.send_message1').attr('data-identity');
    var type = $('.send_message1').attr('data-code-type');
    var obj = $(this);
    if(!$(this).nextAll(".warning").hasClass('hide')){
        return false;
    }
    $.ajax({
        url : web_url + '/head/hunter-home/code.html', 
        type:'post',
        async:false,//同步执行
        dataType:'json',
        data: {mobile: oldMobile, code: code, identity: identity, type: type}, 
        success:function(res) {
            if (res.code == 500) {
                //添加失败的css样式
                obj.nextAll(".warning").html(res.msg).removeClass('hide').show();
                $(this).addClass("border-orange");
            }else{
                obj.nextAll(".warning").addClass('hide').hide();
                obj.removeClass("border-orange");
            }
        },
    })
})



//ajax验证新手机号
$('.mobile').blur(function(){
    var mobile = $(this).val();
    var type = $(this).attr('data-code-type');
    var obj = $(this);
    if(!$(this).nextAll(".warning").hasClass('hide')){
        return false;
    }
    $.ajax({
        url : web_url + '/head/hunter-home/mobile.html', 
        type:'post',
        async:false,//同步执行
        dataType:'json',
        data: {mobile: mobile, type: type}, 
        success:function(res) {
            if (res.code == 500) {
                //添加失败的css样式
                obj.nextAll(".warning").html(res.msg).removeClass('hide').show();
                //$(this).addClass("border-orange");
            }else{
                obj.nextAll(".warning").addClass('hide').hide();
            }
        },
    })
})

//ajax验证新手机验证码
$('.m_code_2').blur(function(){
    var mobile = $('.mobile').val();
    var code = $(this).val();
    var identity = $('.send_message').attr('data-identity');
    var type = $('.send_message').attr('data-code-type');
    var obj = $(this);
    if(!$(this).nextAll(".warning").hasClass('hide')){
        return false;
    }
    $.ajax({
        url : web_url + '/head/hunter-home/code.html', 
        type:'post',
        async:false,//同步执行
        dataType:'json',
        data: {mobile: mobile, code: code, identity: identity, type: type}, 
        success:function(res) {
            if (res.code == 500) {
                //添加失败的css样式
                obj.nextAll(".warning").html(res.msg).removeClass('hide').show();
                $(this).addClass("border-orange");
            }else{
                obj.nextAll(".warning").addClass('hide').hide();
                obj.removeClass("border-orange");
            }
        },
    })
})



//提交新手机号码
$(".editMobile").click(function(){
    var e = window.event || e,
        errNum = 0,
        mobile = $('.mobile').val();
        code = $('.m_code_2').val();
        identity = $('.send_message').attr('data-identity');
        type = $('.send_message').attr('data-code-type');
    if(e.preventDefault){
        e.preventDefault();
    }else{
        window.event.returnValue = false; 
    }

    $('input').trigger('blur');
    errNum = $('span.warning:visible').length;
    if (errNum == 0) {
        $.ajax({
        url : web_url + '/head/hunter-home/edit-mobile.html', 
        type:'post',
        async:false,//同步执行
        dataType:'json',
        data: {mobile: mobile, code: code, identity: identity, type: type}, 
        success:function(res) {
            if (res.code == 200) {
                location.href = web_url + '/head/hunter-home/success.html';
            }else{
                alert(res.msg);
            }
        },
    })
    }
})

//60秒倒计时
var countdown=60;
function setTime(obj) {
   if (countdown == 0) {
        obj.style.background="#53b2fb";
        obj.removeAttribute("disabled");
        obj.value="获取验证码";
        countdown = 60;
        return;
    } else {
        obj.setAttribute("disabled", true);
        obj.value=countdown + "秒后重试";
        obj.style.background="#b2b2b2";
        countdown--;
    }
    setTimeout(function() {
            setTime(obj) }
        ,1000) 
}

//60秒倒计时
var countdown1=60;
function setTime1(obj) {
   if (countdown1 == 0) {
        obj.style.background="#53b2fb";
        obj.removeAttribute("disabled");
        obj.value="获取验证码";
        countdown1 = 60;
        return;
    } else {
        obj.setAttribute("disabled", true);
        obj.value=countdown1 + "秒后重试";
        obj.style.background="#b2b2b2";
        countdown1--;
    }
    setTimeout(function() {
            setTime1(obj) }
        ,1000) 
}

